package com.sfeir.fastcall.utility;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.StreamCorruptedException;

/**
 * Created by :
 * 
 * 		@author SFEIR
 */
public class SerializationHelper {
	
	public static byte[] seralize(Object o) throws IOException{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		ObjectOutputStream oos = new ObjectOutputStream(baos);
		oos.writeObject(o);
		oos.flush();
		oos.close();
		baos.close();
		return baos.toByteArray();
	}
	
	public static Object deseralize(byte[] bytes) throws StreamCorruptedException, IOException, ClassNotFoundException {
		ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
		ObjectInputStream ois = new ObjectInputStream(bais);
		Object o = ois.readObject();
		ois.close();
		bais.close();		
		return o;
	}
	
}
